package com.hc.ex;

import com.hc.enums.ResultEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * 全局异常
 */
@ApiModel(value = "全局异常")
@Getter
@NoArgsConstructor
@ToString
public class GlobalException extends RuntimeException {
    /**
     * 异常错误编码
     */
    @ApiModelProperty(value = "状态码")
    private Integer code;

    public GlobalException(String msg) {
        super(msg);
    }

    /**
     * 接收状态码和消息
     *
     * @param code
     * @param msg
     */
    public GlobalException(Integer code, String msg) {
        super(msg);
        this.code = code;
    }

    /**
     * 接收枚举类型参数
     *
     * @param resultEnum
     */
    public GlobalException(ResultEnum resultEnum) {
        super(resultEnum.getMsg());
        this.code = resultEnum.getCode();
    }
}
